package cdu.sl.mapper;

import cdu.sl.annotation.AutoFill;
import cdu.sl.common.enums.OperationType;
import cdu.sl.domain.po.Flashcard;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 闪存卡Mapper接口
 */
@Mapper
public interface FlashcardMapper extends BaseMapper<Flashcard> {

    @AutoFill(OperationType.INSERT)
    int insert(Flashcard entity);

    /**
     * 根据学习集ID查询闪存卡列表
     *
     * @param studySetId 学习集ID
     * @return 闪存卡列表
     */
    @Select("SELECT * FROM tb_flashcards WHERE study_set_id = #{studySetId} ORDER BY sort_order ASC")
    List<Flashcard> selectByStudySetId(@Param("studySetId") Long studySetId);

    @AutoFill(OperationType.UPDATE)
    @Override
    int update(@Param("et") Flashcard entity, @Param("ew") Wrapper<Flashcard> updateWrapper);
}